package com.ssm.sfzy.controller;

import com.ssm.sfzy.constant.CommonConstant;
import com.ssm.sfzy.entity.FM;
import com.ssm.sfzy.service.FMService;
import com.ssm.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author song
 * @date 2024年03月30日 10:15
 * @version:1.0
 */
@RestController
@CrossOrigin
@RequestMapping("/fm")
public class FMController {
    @Autowired
    private FMService fmService;

    @GetMapping("/find")
    public Object find(
            @RequestParam(defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            FM fm
    ){
        Map<String, Object> map = fmService.findPage(pageNum, pageSize, fm);
        return Result.success(map);
    }

    @GetMapping("/findById/{id}")
    public Object findById(@PathVariable Integer id){
        fmService.findById(id);
        return Result.success(id);
    }

    @PostMapping("/add")
    public Object add(@RequestBody FM fm){
        fmService.add(fm);
        return Result.success(fm);
    }

    @PutMapping("/edit")
    public Object edit(@RequestBody FM fm){
        fmService.edit(fm);
        return Result.success(fm);
    }

    @DeleteMapping("/remove/{id}")
    public Object remove(@PathVariable Integer id){
        fmService.remove(id);
        return Result.success(id);
    }

    @DeleteMapping("/removeBatch/{ids}")
    public Object removeBatch(Integer[] ids){
        fmService.removeBatch(ids);
        return Result.success(ids);
    }

}